package com.yycx.module.bus.provider.controller;


import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.security.OpenUser;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.provider.service.BusDeptService;
import com.yycx.module.system.provider.service.SysFormulaService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 部门控制器
 *
 * @author flyme
 * @date 2020-07-28
 */
@RestController
@RequestMapping("/bus/dept/")
public class BusDeptController extends BaseController<BusDeptService, BusDept> {


    @ApiOperation(value = "部门-分页列表", notes = "部门分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "部门-列表", notes = "部门列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "部门-列表", notes = "部门列表")
    @GetMapping(value = "listByCompanyId")
    public ResultBody listByCompanyId(@RequestParam(required = false) Map params) {
        return ResultBody.ok(bizService.listByCompanyId(params));
    }

    @ApiOperation(value = "部门-添加", notes = "添加部门")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "部门-更新", notes = "更新部门")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "部门-删除", notes = "删除部门")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "部门-详情", notes = "部门详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "设置部门状态", notes = "设置部门状态")
    @PostMapping(value = "setDeptState")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "ids", required = true, value = "主键", paramType = "form"),
        @ApiImplicitParam(name = "deptState", required = true, value = "状态值", paramType = "form")
    })
    public ResultBody setDeptState(@RequestParam(required = false) Map map, @RequestParam(value = "deptState") Integer deptState) {
        return bizService.setState(map, "deptState", deptState);
    }


    @ApiOperation(value = "同步海鹰数据", notes = "同步海鹰数据")
    @PostMapping(value = "syncHyData")
    public ResultBody syncHyData() {
        OpenUser openUser = OpenHelper.getUser();
        bizService.syncHyData(openUser);
        return ResultBody.ok("同步完成");
    }


}
